package com.lz.service.smsmail;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import com.lz.service.smsmail.filter.AuthFilter;
import com.lz.service.smsmail.filter.FlowLimitFilter;
import com.lz.service.smsmail.filter.PreFilter;

/** 
 * 应用配置
 * 1、配置过滤器(可设置顺序)
 * @author likejian
 *
 */
@Component
public class FilterConfig { 

	@Value("${spring.application.name}")
	private String application;

    @Bean
    public FilterRegistrationBean  filterRegistrationBeanFlowLimitFilter() {
    	FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    	FlowLimitFilter actionFilter = new FlowLimitFilter();
    	registrationBean.setFilter(actionFilter);
    	List<String> urlPatterns = new ArrayList<String>();
    	urlPatterns.add("/*");
    	registrationBean.setUrlPatterns(urlPatterns);
    	registrationBean.setOrder(1);
    	return registrationBean;
    }
    
    @Bean
    public FilterRegistrationBean  filterRegistrationBeanPreFilter() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        PreFilter actionFilter = new PreFilter(application);
        registrationBean.setFilter(actionFilter);
        List<String> urlPatterns = new ArrayList<String>();
        urlPatterns.add("/*");
        registrationBean.setUrlPatterns(urlPatterns);
        registrationBean.setOrder(2);
        return registrationBean;
    }
    
    @Bean
    public FilterRegistrationBean  filterRegistrationBeanAuthFilter() {
    	FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    	AuthFilter actionFilter = new AuthFilter();
    	registrationBean.setFilter(actionFilter);
    	List<String> urlPatterns = new ArrayList<String>();
    	urlPatterns.add("/*");
    	registrationBean.setUrlPatterns(urlPatterns);
    	registrationBean.setOrder(3);
    	return registrationBean;
    }

}